---
draft: true
title: How I use LaTeX as a uni student
date: 2022-11-01
description: A post about how I use LaTeX to write documents as a Uni student.
tags:
    - latex
    - notetaking
---

# Introduction

Hello there! It has been a _very_ long time since I wrote something here. I didn't know being a uni student would make me so occupied with a lot of stuff.
Anyway, since I am now a uni student I get to use LaTeX more often, which is great!
Our lecturer didn't told us to use LaTeX specifically, but I've been wanting to have a chance to use it when I was still in high school, and now I have the chance to use it for every assignments.

There are a lot for me to learn, so I decided to write them all down here so that I won't forget a thing and maybe you can also get something useful from this note!

# What is LaTeX?

First of all, if you don't know what LaTeX is, quoting from [its website](https://www.latex-project.org/):

> "LaTeX is a high-quality typesetting system; it includes features designed for the production of technical and scientific documentation. LaTeX is the de facto standard for the communication and publication of scientific documents."

In a simpler term, it's basically a way to write high-quality document without ever touching a rich text editor such as Microsoft Word by using a language that will be compiled to a `.pdf`. If you know Markdown, LaTeX is like a more complex and fancy version of it.

It is usually used to write scientific documents where it contains a lot of math equations. Though, I usually use it to write regular documents with some codeblocks. The result looks more neat and it took less time for me compared to using a WYSIWYG editor.

# My LaTeX Setup

## LaTeX Installation

I was previously using ArchLinux, so I can just easily install LaTeX from the package manager. Now, because of several reasons, I'm using Windows and WSL2 Debian on my Laptop. Installing it inside WSL is a breeze but installing it on Windows is a bit cumbersome. I couldn't use `winget` (for some reason?) so I need to grab the [TeXLive installer](https://www.tug.org/texlive/). I didn't know if the installed package is quite big, around 7GB on my machine.

At first, I decided to install LaTeX inside WSL, but then all my other assignments are more suitable if I put it inside Windows. Opening Windows drive from WSL is sluggish. Although, I still have it installed on both places.

## Editor

It doesn't matter which editor you use. LaTeX files are just plain text files. As long as you can edit the text, you'll be fine. But, I recommend you to use a text editor that has some sort of autocomplete or suggestion because there are _a lot_ of LaTeX macros that you can use and having a "smart" editor will help you.

I used [Neovim](https://neovim.io) as my editor with [VimTeX](https://github.com/lervag/vimtex) plugin before, but now I'm using [Visual Studio Code](https://code.visualstudio.com/) with [Latex Workshop](https://github.com/James-Yu/LaTeX-Workshop) extension.

# LaTeX Basics

I will give a short introductory to LaTeX basic to help you get started. Let's try to make a document with a cover and some contents. To make it easier for me, this section assumes you're using [Visual Studio Code](https://code.visualstudio.com/) with [Latex Workshop](https://github.com/James-Yu/LaTeX-Workshop) installed since that's what I use. For other editor/CLI usage, please google it yourself, sorry :)

This section only covers what I used through uni, so it won't cover _everything_ but it should be enough to get you started.

## Creating document

LaTeX file have a `.tex` extension. When we compile it, it will produce a lot of auxiliary files so make sure you create the file inside a directory. For example, I'll have mine in `latex-example/my-document.tex`.

### Document Class

In LaTeX, we have something called `documentclass`. It basically tells the latex compiler which type of document we want to create. I usually use the `article` class because that's what I use LaTeX for, but there are also a bunch of other classes.

| Name         | Description                                                                                                                          |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| **article**  | For articles in scientific journals, presentations, short reports, program documentation, invitations, ...                           |
| **IEEEtran** | For articles with the IEEE Transactions format.                                                                                      |
| **proc**     | A class for proceedings based on the article class.                                                                                  |
| **minimal**  | It is as small as it can get. It only sets a page size and a base font. It is mainly used for debugging purposes.                    |
| **report**   | For longer reports containing several chapters, small books, thesis, ...                                                             |
| **book**     | For books.                                                                                                                           |
| **slides**   | For slides. The class uses big sans serif letters.                                                                                   |
| **memoir**   | For sensibly changing the output of the document. It is based on the book class, but you can create any kind of document with it [1] |
| **letter**   | For writing letters.                                                                                                                 |
| **beamer**   | For writing presentations (see [LaTeX/Presentations](https://en.wikibooks.org/wiki/LaTeX/Presentations)).                            |

The table above lists a few of common document classes, but there are also a lot more of them which you can see [on this CTAN page](https://ctan.org/topic/class).

Let's use the `article` document class. To apply a document class, we use the `\documentclass` macro. We need to write it at the very top of our file before everything else. Our file should now look like this:

```tex
\documentclass{article}
```

It is not ready for anything just yet, so don't bother trying to compile it.

If you use Visual Studio Code with Latex Workshop, you should be able to place your cursor inside the curly braces of `\documentclass{}` and press `ctrl+space`, it should show a suggestion list for the available document classes.

### Hello World

To write the content of a document in latex, we use the `\begin{document}` and `\end{document}` macro. The `\begin{}` and `\end{}` is used to start and end an environment. It marks a section of our document, think of it as a curly braces in some programming languages. There will be other environments that I wlil discuss later in this post, don't worry!

Inside the document environment, let's try to write some text. For example, a good ol' `Hello world`. Our LaTeX file should now look like this.

```tex
\documentclass{article}

\begin{document}
Hello World!
\end{document}
```

You can choose whether or not to indent the text. I usually indent it by a level for any new environments, but I don't do it for the document environment to save space because it's the root environment.

### Compiling

We can now try to compile our document into a pdf! Since we're using LaTeX workshop, there should be a little play button at the top right corner of the editor.

![hello-world-latex-screenshot](/assets/posts/how-i-use-latex-as-a-uni-student/vscode-hello-world-latex.png)

After pressing that button, there should be a bunch of files generated including a pdf file that we can open. It should contain the text `Hello World!`. Nice, we compiled our first LaTeX document.

### Text Styling

When we're writing documents, of course, we need more than just 1 style of text. We usually want bold, italic, heading, subheading, etc. When using LaTeX, we can use the macros that it provides. Here are some of them:

#### Section and SubSection Heading

To create a section heading, we can simply use the `\section{}` macro and it should create a section heading along with the numbering. We don't need to fiddle around with the section number, which is great! There is also the `\subsection{}` heading to create a sub section heading. It will automatically derive the section heading number. For example, if we have number **1** for our section heading, the sub section heading should have the number **1.2**.

There is also a `\subsubsection{}` macro if you want to go a level deeper. I rarely use this though, usually 2 levels deep is enough for my needs. Just like the subsection heading, it will derive its parent number. For example, if we have a **1.1** sub section number, we should have **1.1.1** sub sub section number.

Let's try to create our first section, subsection, and subsubsection headings! Back to our tex file, let's create 3 types of headings. The first one would be a regular heading, the second one would be a heading with 2 subsection, and the last one would be a heading with 2 subsection with 2 and 3 subsubsections on its subsection.

Make sure you write these inside the document environment.

```tex
\section{My first section}

\section{My second section}

\subsection{My first subsection}

\subsection{My second subsection}

\section{My third section}

\subsection{My third subsection}

\subsubsection{My first subsubsection}

\subsection{My fourth subsection}

\subsubsection{My second subsubsection}

\subsubsection{My third subsubsection}
```

If we compile our document using the play button again and see the result. Although, Latex Workshop should automatically rebuild your tex file whenever it has any changes. If we check our pdf file again, it should now look like this:

![Latex Headings](/assets/posts/how-i-use-latex-as-a-uni-student/latex-headings.png)

#### Bold Text

To make our text bold, we can use the `\textbf{}` macro. For example, to write **this is a bold text**, we can type `\textbf{this is a bold text}`.

#### Italic Text

There are two ways of writing an italicised text. The first one is to use `\textit{}` macro like `\textit{this is an italic text}`, but you can also the `\emph{}` macro. The different is that the `\textit{}` macro will always make the text look italic while the `\emph{}` macro can be changed. For more details about their differences, you can refer to [this stackexchange comment](https://tex.stackexchange.com/a/1983)

### Table of Contents

The good thing about LaTeX is we don't need to worry about the formatting details. That includes generating a table of contents. To generate that, we can just invoke the `\tableofcontents` macro and voila, we have ourself a table of contents filled with our headings.

// TODO(elianiva): finish the article

## Closing Notes

I think that's all for this post. There are a bunch more that I want to write, but I think it'd be better for me to split them into their own post so that this post doesn't get super lengthy. I hope you learned something from this post, thanks for reading!

Oh! by the way, you can read this article in form of LaTeX found on [this Github repo](https://github.com/elianiva/latex-basics). Feel free to also use it as a reference :)
